package com.fr.base;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager2;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class FormLayout
  implements LayoutManager2, Serializable
{
  private Map componentMap = new HashMap();

  public void addLayoutComponent(Component paramComponent, Object paramObject)
  {
    if (paramObject == null)
      throw new IllegalArgumentException("constraints can't be null");
    if (!(paramObject instanceof FormData))
      throw new IllegalArgumentException("constraints must be a" + FormData.class.getName() + "instance");
    synchronized (paramComponent.getTreeLock())
    {
      this.componentMap.put(paramComponent, (FormData)paramObject);
    }
  }

  /**
   * @deprecated
   */
  public void addLayoutComponent(String paramString, Component paramComponent)
  {
  }

  public float getLayoutAlignmentX(Container paramContainer)
  {
    return 0.0F;
  }

  public float getLayoutAlignmentY(Container paramContainer)
  {
    return 0.0F;
  }

  public void invalidateLayout(Container paramContainer)
  {
  }

  public Dimension maximumLayoutSize(Container paramContainer)
  {
    return paramContainer.getMaximumSize();
  }

  public Dimension minimumLayoutSize(Container paramContainer)
  {
    return paramContainer.getMinimumSize();
  }

  public Dimension preferredLayoutSize(Container paramContainer)
  {
    Dimension localDimension1 = new Dimension(0, 0);
    int i = paramContainer.getComponentCount();
    for (int j = 0; j < i; ++j)
    {
      Component localComponent = paramContainer.getComponent(j);
      if (localComponent.isVisible())
      {
        Dimension localDimension2 = localComponent.getPreferredSize();
        localDimension1.height = Math.max(localDimension1.height, localDimension2.height);
        localDimension1.width += localDimension2.width;
      }
    }
    Insets localInsets = paramContainer.getInsets();
    localDimension1.width += localInsets.left + localInsets.right;
    localDimension1.height += localInsets.top + localInsets.bottom;
    return localDimension1;
  }

  public void removeLayoutComponent(Component paramComponent)
  {
    synchronized (paramComponent.getTreeLock())
    {
      this.componentMap.remove(paramComponent);
    }
  }

  public void layoutContainer(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
    }
    int i = paramContainer.getWidth();
    int j = paramContainer.getHeight();
    Component[] arrayOfComponent = paramContainer.getComponents();
    for (int k = 0; k < arrayOfComponent.length; ++k)
    {
      Component localComponent = arrayOfComponent[k];
      FormData localFormData = (FormData)this.componentMap.get(localComponent);
      if (localFormData == null)
        break label588:
      float f1 = localFormData.left;
      float f2 = localFormData.right;
      float f3 = localFormData.top;
      float f4 = localFormData.bottom;
      int l = -1;
      int i1 = -1;
      int i2 = 0;
      int i3 = 0;
      Dimension localDimension = localComponent.getPreferredSize();
      if (localDimension == null)
        throw new RuntimeException("the component must have preferred-size");
      i2 = localComponent.getPreferredSize().width;
      i3 = localComponent.getPreferredSize().height;
      if ((f1 != -1.0F) && (f3 != -1.0F))
        if ((f1 > 1.0F) || (f1 == 0.0F))
        {
          l = (int)f1;
          i1 = (int)f3;
        }
        else
        {
          l = (int)(f1 * i);
          i1 = (int)(f3 * j);
        }
      else if ((f2 != -1.0F) && (f4 != -1.0F))
        if ((f2 == 0.0F) || (f2 > 1.0F))
        {
          l = (int)(i - f2);
          i1 = (int)(j - f4);
        }
        else
        {
          l = i - (int)(f2 * i) - i2;
          i1 = j - (int)(f4 * j) - i3;
        }
      else if ((f1 != -1.0F) && (f4 != -1.0F))
        if ((f1 == 0.0F) || (f1 > 1.0F))
        {
          l = (int)f1;
          i1 = (int)(j - f4);
        }
        else
        {
          l = (int)(f1 * i);
          i1 = j - (int)(f4 * j) - i3;
        }
      else if ((f2 != -1.0F) && (f3 != -1.0F))
        if ((f2 == 0.0F) || (f2 > 1.0F))
        {
          l = (int)(i - f2);
          i1 = (int)f3;
        }
        else
        {
          l = i - (int)(f2 * i) - i2;
          i1 = (int)(f3 * j) - i3;
        }
      else
        throw new IllegalArgumentException("cannot be all null!");
      for (int i4 = 0; i4 < arrayOfComponent.length; ++i4)
      {
        if (k == i4)
          break label564:
        int i5 = arrayOfComponent[i4].getX();
        int i6 = arrayOfComponent[i4].getY();
        if (Math.abs(i6 - i1) < 10)
        {
          if ((l - i5 < 30) && (l - i5 > 20))
          {
            l = i5 + i2;
            i1 = i6;
            break;
          }
          if ((l - i5 < -20) && (l - i5 > -30))
          {
            l = i5 - i2;
            i1 = i6;
            break;
          }
        }
      }
      localComponent.setBounds(l, i1, i2, i3);
      localComponent.repaint();
    }
    label564: label588: return;
  }

  public FormData getComponentData(Component paramComponent)
  {
    synchronized (paramComponent.getTreeLock())
    {
      return ((FormData)this.componentMap.get(paramComponent));
    }
  }
}